﻿using System;
using System.Net;
using caedisi.Models;
using System.Linq;
using caedisi.Helpers;
using System.Collections.ObjectModel;
using caedisi.Common;

namespace caedisi.Web.DataModel
{
    public partial class Cell
    {
        /// <summary>
        /// Called when [cell state type id changed].
        /// We need to synchronize the state of the Cell with the one stored in the simulation dictionary.
        /// </summary>
        partial void OnCellStateTypeIdChanged()
        {
            if (_SimulationIterationItem != null)
            {
                if (this._SimulationIterationItem.CellStateTypeId != this.CellStateTypeId)
                {
                    this._SimulationIterationItem.CellStateTypeId = this.CellStateTypeId;

                    if (this._SimulationIterationItem.CellStateTypeId == ((int)EnumCellStateType.Decontaminated))
                        this.SimulationIterationItem.ImmunityTimerValue = 0;
                    else
                        this.SimulationIterationItem.ImmunityTimerValue = null;
                }
            }
        }

        private SimulationIterationItem _SimulationIterationItem;
        /// <summary>
        /// Gets or sets the simulation iteration item.
        /// </summary>
        /// <value>
        /// The simulation iteration item.
        /// </value>
        public SimulationIterationItem SimulationIterationItem
        {
            get
            {
                return _SimulationIterationItem;
            }
            set
            {
                if (_SimulationIterationItem != value)
                {
                    _SimulationIterationItem = value;
                    this.RaisePropertyChanged("SimulationIterationItem");

                    OnSimulationIterationItemChanged();
                }
            }
        }

        private void OnSimulationIterationItemChanged()
        {
            this.CellStateTypeId = this.SimulationIterationItem.CellStateTypeId;
        }
    }
}
